//
//  WUDetailViewController.m
//  Home
//
//  Created by 吴军虎吴军虎 on 16/5/5.
//  Copyright © 2016年 LanJue. All rights reserved.
//

#import "WUDetailViewController.h"
#import "YHYButtonTabBar.h"
#import "WUFindNameCell.h"
#import "WUMyHighlightcell.h"
#import "WUexperienceCell.h"
#import "WUPictureCell.h"
#import "UIView+Five.h"
#import "WSTools.h"
#import "LewPopupViewAnimationSpring.h"
#import "YHYWUViewController.h"
#import "YHYDesignerPersonController.h"


@interface WUDetailViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,YHYTabBarGouTongAndShouCang,WUexperienceCellDelegate>
{
    NSInteger rowHeight;
}


@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) WSCustomButton *shareBtn;
@property (nonatomic, strong) WSCustomButton *backBtn;
@property (nonatomic, assign) BOOL isSelect;
@property (nonatomic,assign)BOOL isON;/**<点击沟通*/
@property (nonatomic,retain)UIView *alertView;
@property (nonatomic,assign)BOOL isSelrct;
@property (nonatomic,assign) BOOL isBa;
@property (nonatomic,strong) NSString *testStr;
@property (nonatomic,strong) YHYButtonTabBar *bottonView;

@property (nonatomic, strong) UIView *view1;
@property (nonatomic, strong) UIView *view2;

@end

@implementation WUDetailViewController

-(void) viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden=YES;
    self.navigationController.navigationBarHidden=NO;
      self.title=@"任务详情";
}

-(void) viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden=NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSLog(@"dddddddddddddd%@",self.model);
    rowHeight = [WSTools cptStringHeight:@"雪花\n雪花\n雪花\n雪花\n雪花\n雪花" withFont:[UIFont systemFontOfSize:13 * AUTO_WIDTH] width:([UIScreen mainScreen].bounds.size.width - (30 * AUTO_WIDTH))] + 77 * AUTO_WIDTH;
    self.testStr = @"雪花啤酒广告平面拍摄代言人\n视频作品：凯撒柔思面膜广告微电影饰演女二\n杭州野生动物园宣传片.饰演情侣.\n浙江少儿频道微电影《绽放》饰演女主婷婷.\n浙江少儿频道微电影《绽放》饰演女主婷婷.\n浙江少儿频道微电影《绽放》饰演女主婷婷.\n浙江少儿频道微电影《绽放》饰演女主婷婷.\n浙江少儿频道微电影《绽放》饰演女主婷婷.\n浙江少儿频道微电影《绽放》饰演女主婷婷.";
    
    _isSelect = YES;
    [self creatView];
    _isSelrct = NO;
    _isON = NO;
     _bottonView= [[YHYButtonTabBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50 * AUTO_WIDTH)];
   
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    [user objectForKey:[NSString stringWithFormat:@"%ld",(long)self.indexPath.row]];
//    NSLog(@"dddddd=%@",[user objectForKey:[NSString stringWithFormat:@"%ld",(long)self.indexPath.row]]);
    if ([user objectForKey:[NSString stringWithFormat:@"%ld",(long)self.indexPath.row]] == 0  ) {
        
        _bottonView.gouTongL.text = @"立即沟通"; // 判断时 需要掉接口 创建微简历 字段
        
        
             //

        }
    else {
        _bottonView.xinImageView2.image = [UIImage imageNamed:@"tong"];
        
        _bottonView.gouTongL.text = @"继续沟通";
        
    }
    _bottonView.delegate = self;
    [self.view addSubview:_bottonView];
    [_bottonView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 50 * AUTO_WIDTH));
        make.left.bottom.mas_equalTo(@0);
    }];
    
    
    
    UIImageView *viewIV = [UIImageView new];
    viewIV.image = [UIImage imageNamed:@"purse_shadow"];
    //viewIV.backgroundColor = [UIColor redColor];
    [self.view addSubview:viewIV];
    
    [viewIV mas_makeConstraints:^(MASConstraintMaker *make) {
        //        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 100 * AUTO_WIDTH));
        make.left.bottom.mas_equalTo(@0);
        //make.left.mas_equalTo(self.view);
        make.right.mas_equalTo(self.view);
        make.height.mas_equalTo(60 * AUTO_HEIGHT);
        
    }];

  
    
    self.view.layer.contents=nil;
    
    //view1
    _view1=  [[UIView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height/2-100)];
    _view1.backgroundColor=HS;
    //***********************
    //这个属性可以设置寄宿图显示的区域
    _view1.layer.contentsRect=CGRectMake(0.0,0.0,1,0.5);
    
    
    [self.view addSubview:_view1];
    
    //view2
    _view2=[[UIView alloc]initWithFrame:CGRectMake(0,self.view.frame.size.height/2,self.view.frame.size.width, self.view.frame.size.height/2-64)];
    
    _view2.backgroundColor=HS;
    
    _view2.layer.contentsRect=CGRectMake(0.0,5.0,1,0.5);
    
    
    [self.view addSubview:_view2];
    
    
    //********************
    //属性动画
    [UIView animateWithDuration:1.0 animations:^{
        
        _view1.frame=CGRectMake(0,-self.view.frame.size.height/2-100,self.view.frame.size.width,self.view.frame.size.height/2-100);
        
        _view2.frame=CGRectMake(0,self.view.frame.size.height+self.view.frame.size.height/2 ,self.view.frame.size.width,self.view.frame.size.height/2);
        
        
    } completion:^(BOOL finished) {
        [_view1 removeFromSuperview];
        [_view2 removeFromSuperview];
    }];

}

- (void)creatView{
    
    //    self.shareBtn = [WSCustomButton buttonWithType:UIButtonTypeCustom];
    //    self.shareBtn.frame = CGRectMake(0, 0, 30, 30);
    //    [self.shareBtn setImage:[[UIImage imageNamed:@"navigation_share"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
    //    [self.shareBtn addTarget:self action:@selector(btn1Action:) forControlEvents:UIControlEventTouchUpInside];
    //    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:_shareBtn];
    
    
    self.backBtn = [WSCustomButton buttonWithType:UIButtonTypeCustom];
    self.backBtn.frame = CGRectMake(0, 0, 30, 30);
    [self.backBtn setImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
    [self.backBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_backBtn];
    
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.sectionInset = UIEdgeInsetsMake(5 * AUTO_WIDTH, 0, 0 * AUTO_WIDTH, 0);
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 70) collectionViewLayout:flowLayout];
    
    flowLayout.minimumLineSpacing =8 * AUTO_HEIGHT;
    self.collectionView.backgroundColor = LV;
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.view addSubview:self.collectionView];
    [_collectionView registerClass:[WUFindNameCell class] forCellWithReuseIdentifier:@"WUFindNameCell"];
    
    [_collectionView registerClass:[WUMyHighlightcell class] forCellWithReuseIdentifier:@"WUMyHighlightcell"];
    
    [_collectionView registerClass:[WUexperienceCell class] forCellWithReuseIdentifier:@"WUexperienceCell"];
    
    [_collectionView registerClass:[WUPictureCell class] forCellWithReuseIdentifier:@"WUPictureCell"];
    
    [_collectionView reloadData];
    
}


-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    
    if (_isSelect == YES) {
        return 4;
    }
    else if (_isSelect == NO){
        return 4 + 3;
        //  [_collectionView reloadData];
    }
    return 0;
    
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.row==0) {
        
        return CGSizeMake(SCREEN_WIDTH - (8 * AUTO_WIDTH * 2), 80.00 * AUTO_WIDTH);
        
    }else if (indexPath.row ==1){
        
        return CGSizeMake(SCREEN_WIDTH - (8 * AUTO_WIDTH * 2), 145.00 * AUTO_WIDTH);
        
    }else if(indexPath.row ==2){
        
         return CGSizeMake(SCREEN_WIDTH - (8.00 * AUTO_WIDTH * 2), rowHeight +10 * AUTO_HEIGHT);
        
    }else{
    
        return CGSizeMake(SCREEN_WIDTH - (8.00 *AUTO_WIDTH *2), 300 *AUTO_HEIGHT);
    }
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        
        static NSString *name = @"WUFindNameCell";
        WUFindNameCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:name forIndexPath:indexPath];
       
        [cell settingRegisnModel:self.model];
        return cell;
    }
    if (indexPath.row == 1) {
        static NSString *str = @"WUMyHighlightcell";
        WUMyHighlightcell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:str forIndexPath:indexPath];
        [cell settingRegisnModel:self.model];
        return cell;
    }
     else  if(indexPath.row ==2){
        
        static NSString *str = @"WUexperienceCell";
        WUexperienceCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:str forIndexPath:indexPath];
         cell.delegate=self;
        return cell;
     }else{
     
         static NSString *prict=@"WUPictureCell";
         WUPictureCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:prict forIndexPath:indexPath];
         [cell settingRegisnModel:self.model];
         return cell;
     }
    
   
    
    // return nil;
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    //    if (indexPath.row == 5) {
    //        NSLog(@"fsd");
    //    }
    
}

////协议
//- (void)presentNextShow{
//    _isSelect = NO;
//    YHYMoreCaseCell *cell = (YHYMoreCaseCell *)[_collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:5 inSection:0]];
//    
//    [cell.button removeFromSuperview];
//    [_collectionView reloadData];
//}

- (void)backAction:(UIButton *)back{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)YHYgongTongTabBar{
    if (!self.isON) {
        
        if (self.isBa) {
            [self animateView];
            
            [self lew_presentPopupView:_alertView animation:[LewPopupViewAnimationSpring new] dismissed:^{
                
            }];

        }else{
        
        
            YHYWUViewController *yhy=[[YHYWUViewController alloc]init];
            [self.navigationController pushViewController:yhy animated:YES];
            _bottonView.xinImageView2.image = [UIImage imageNamed:@"tong"];
            
            _bottonView.gouTongL.text = @"继续沟通";
        }
        self.isBa =!self.isBa;
        
    }
    else{
        
        self.alertView.hidden = YES;
        //self.myScrollView.alpha = 1.0;
       
    }
    
    self.isON =! self.isON;
    
}
- (void)findButtonClickWith:(FINDBUTTONCLICK)click{
    
    if (click == FINDBUTTONCLICKCOLLECT) {
        
        click = FINDBUTTONCLICKCOLLECT;
        self.isSelrct = !self.isSelrct;
        if (self.isSelrct) {
            //self.xinImageView.image = [UIImage imageNamed:@"heart"];
            [self.view Message:@"收藏成功" HiddenAfterDelay:1];
        }
        else{
            NSLog(@"dd");
             //self.xinImageView.image = [UIImage imageNamed:@"heartShi"];
           [self.view Message:@"取消收藏" HiddenAfterDelay:1];
            
        }
        
        
    }
    
    
    
    if (click == FINDBUTTONCLICKTALK) {
        [self YHYgongTongTabBar];
        
        NSString *passWord= [NSString stringWithFormat:@"%ld",(long)self.indexPath.row];
        NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
        
        [user setObject:passWord forKey:passWord];
    }
    
}


- (void)animateView{


    self.isON= !self.isON;
    self.alertView = [[UIView alloc]init];
    self.alertView.backgroundColor = [UIColor colorWithWhite:0.985 alpha:1.000];
    [self.view addSubview:self.alertView];
    
    
    [UIView animateWithDuration:0.08 animations:^{
        
        //        self.aView.frame = CGRectMake(40, 90, 120, 60);
        self.alertView.center = CGPointMake(self.view.frame.size.width/2 , 0 );
        self.alertView.frame = CGRectMake(30.00*AUTO_WIDTH,0, self.view.frame.size.width - 60.00*AUTO_WIDTH, 250.00*AUTO_WIDTH);
        //
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:0.005 animations:^{
            self.alertView.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2 );
            
            
            self.alertView.alpha = 1;
            
        }];
        
        
    }];
    
    self.alertView.layer.masksToBounds = YES;
    self.alertView.layer.cornerRadius = 15.00*AUTO_WIDTH;
    self.alertView.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);
    
    
    UIButton *quxiaoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [quxiaoButton setImage:[UIImage imageNamed:@"picker_can"] forState:UIControlStateNormal];
    [quxiaoButton addTarget:self action:@selector(quxiaoAction:) forControlEvents:UIControlEventTouchUpInside];
    quxiaoButton.backgroundColor = [UIColor whiteColor];
    [self.alertView addSubview:quxiaoButton];
    [quxiaoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.alertView).offset(7.00*AUTO_WIDTH);
        make.right.equalTo(self.alertView.mas_right).offset(-10.00*AUTO_WIDTH);
        make.size.mas_equalTo(CGSizeMake(20.00*AUTO_WIDTH, 20.00*AUTO_WIDTH));
        
    }];
    
    UIImageView *tishiImageview = [[UIImageView alloc]init];
    tishiImageview.image = [UIImage imageNamed:@"gantan"];
    //tishiImageview.backgroundColor = [UIColor whiteColor];
    [self.alertView addSubview:tishiImageview];
    [tishiImageview  mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.alertView).offset(25.00*AUTO_WIDTH);
        make.left.equalTo(self.alertView).offset((self.view.frame.size.width - 115.00*AUTO_WIDTH)/2);
        make.size.mas_equalTo(CGSizeMake(95.00/2*AUTO_WIDTH, 95.00/2*AUTO_WIDTH));
        
    }];
    
    UILabel *aLabel = [[UILabel alloc]init];
    aLabel.backgroundColor =[UIColor colorWithWhite:0.985 alpha:1.000];
    [self.alertView addSubview:aLabel];
    aLabel.text = @"立即创建主页";
    aLabel.textColor = HS;
    aLabel.textAlignment = NSTextAlignmentCenter;
    aLabel.font = [UIFont fontWithName:ZIXING size:TEXTCONTENTFONT*TEXTWEIGHT];
    [aLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(tishiImageview.mas_bottom).offset(20.00*AUTO_WIDTH);
        make.left.equalTo(self.alertView).offset(100.00*AUTO_WIDTH);
        make.right.equalTo(self.alertView.mas_right).offset(-100.00*AUTO_WIDTH);
        // make.size.mas_equalTo(CGSizeMake(22, 30.00*HEIGHT));
        make.height.mas_equalTo(30 * AUTO_HEIGHT);
        
    }];
    UILabel *bLabel = [[UILabel alloc]init];
    bLabel.backgroundColor =[UIColor colorWithWhite:0.985 alpha:1.000];
    [self.alertView addSubview:bLabel];
    bLabel.text = @"与海量商家在线交流";
    aLabel.textColor = HS;
    bLabel.textAlignment = NSTextAlignmentCenter;
    bLabel.font = [UIFont fontWithName:ZIXING size:TEXTCONTENTFONT*TEXTWEIGHT];
    [bLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(aLabel.mas_bottom).offset(20.00*AUTO_WIDTH);
        make.left.equalTo(self.alertView).offset(60.00*AUTO_WIDTH);
        make.right.equalTo(self.alertView.mas_right).offset(-60.00*AUTO_WIDTH);
        // make.size.mas_equalTo(CGSizeMake(22, 30.00*HEIGHT));
        make.height.mas_equalTo(30 * AUTO_HEIGHT);
        
    }];
    
    UIButton *chungajianButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [chungajianButton addTarget:self action:@selector(chuangjianActon:) forControlEvents:UIControlEventTouchUpInside];
    chungajianButton.layer.masksToBounds = YES;
    chungajianButton.layer.cornerRadius = LITTLETEXTFONT*TEXTWEIGHT;
    [chungajianButton setTitle:@"创建主页" forState:UIControlStateNormal];
    chungajianButton.backgroundColor  = GH;
    chungajianButton.titleLabel.font = [UIFont fontWithName:ZIXING size:TEXTCONTENTFONT*TEXTWEIGHT];
    [chungajianButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [self.alertView addSubview:chungajianButton];
    [chungajianButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.alertView.mas_bottom).offset(-20.00*AUTO_WIDTH);
        make.right.equalTo(self.alertView.mas_right).offset(-80.00*AUTO_WIDTH);
        make.left.equalTo(self.alertView).offset(80.00*AUTO_WIDTH);
        //  make.size.mas_equalTo(CGSizeMake(20.00*WEIGHT,30.00*WEIGHT));
        make.height.mas_equalTo(30 * AUTO_HEIGHT);
        
    }];
    
    
}

-(void) changeShowState:(BOOL) state
{
    
    if (!state) {
        
        rowHeight = [WSTools cptStringHeight:_testStr withFont:[UIFont systemFontOfSize:13 * AUTO_WIDTH] width:(SCREEN_WIDTH - (30 * AUTO_WIDTH))] + 86 * AUTO_WIDTH;
    }
    else {
    
        
        rowHeight = [WSTools cptStringHeight:@"雪花\n雪花\n雪花\n雪花\n雪花\n雪花" withFont:[UIFont systemFontOfSize:13 * AUTO_WIDTH] width:(SCREEN_WIDTH - (30 * AUTO_WIDTH))] + 77 * AUTO_WIDTH;
    }
    [self.collectionView reloadData];
}


-(void) chuangjianActon:(UIButton *) btn
{
    [self lew_dismissPopupView];
    YHYDesignerPersonController *designer=[[YHYDesignerPersonController alloc]init];
    [self.navigationController pushViewController:designer animated:YES];


}



-(void) quxiaoAction:(UIButton*) btn
{
    [self lew_dismissPopupView];
    
    self.isON=NO;
    self.alertView.alpha=0;
}

-(void) Back:(UIButton *) btn
{

    [self .navigationController popViewControllerAnimated:YES];
    
}

@end

